package top.qingyunge.autumn.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import top.qingyunge.autumn.interceptor.LoginInterceptor;

/**
 * 配置类，用于自动配置拦截器、参数解析器等web组件
 */

@Configuration
public class WebConfig implements WebMvcConfigurer{
    //注册自定义登录拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor()).excludePathPatterns(
                "/doc.html",
                "/webjars/**",
                "/v3/api-docs/**",
                "/swagger-ui.html",
                "/static/**",
                "/swagger-resources"
        );
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
// 配置拦截器访问静态资源
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/favicon.ico")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}